<template>
  <div>
    <van-field label="手机号" v-model="form.name"></van-field>
    <select name="" id="" v-model="form.role_id">
      <option v-for="i in roles" :key="i.id" :value="i.id">{{ i.NAME }}</option>
    </select>
    <van-button round style="background-color: azure" @click="add">添加</van-button>
  </div>
</template>

<script>
export default {
  name: "add_admin",
  data() {
    return {
      form: {},
      roles: []
    }
  },
  methods: {
    getroles() {
      this.$axios.get('/admin//roles').then(res => {
        if (res.data.code == 200) {
          this.roles = res.data.list1
        }
      })
    },
    add() {
      if (this.form.name == '' || this.form.name == null || this.form.name == undefined) {
        alert('手机号不能为空')
        return
      }
      let re = /^1[3-9]\d{9}$/
      if (!re.test(this.form.name)) {
        alert('手机不符合格式')
        return
      }
      this.$axios.post('/admin/user', this.form).then(res => {
        if (res.data.code == 200) {
          alert('添加成功')
          this.form = {}
        } else {
          alert(res.data.mes)
        }
      })

    }

  },
  mounted() {
    this.getroles()
  }
}
</script>

<style scoped>

</style>
